package org.alex.mqtt.common.utils;

import io.netty.handler.codec.mqtt.*;

/**
 * mqtt消息转换工具
 */
public class MqttMessageUtil {

    /**
     * 将code转换为Connect Ack消息体
     */
    public static MqttConnAckMessage getConnectAckMessage(MqttConnectReturnCode returnCode, boolean sessionPresent){
        MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
        MqttConnAckVariableHeader variableHeader = new MqttConnAckVariableHeader(returnCode,sessionPresent);
        return new MqttConnAckMessage(fixedHeader,variableHeader);
    }
}
